package com.ruoyi.system.mapper;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.domain.OrderInfoBO;
import com.ruoyi.system.domain.PropertyFeedback;
import com.ruoyi.system.domain.Story;
import org.apache.ibatis.annotations.*;


import java.util.List;

public interface PropertyMapper {

    /**
     * 通过ID查询order
     *
     * @param id
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_info where id = #{id}")
    @Results({
            @Result(id = true,property = "id",column = "ID"),
            @Result(property = "keyId",column = "KEY_ID"),
            @Result(property = "typeName",column = "TYPE_NAME"),
            @Result(property = "userName",column = "USER_NAME"),
            @Result(property = "storied",column = "STORIED"),
            @Result(property = "address",column = "ADDRESS"),
            @Result(property = "describe",column = "DESCRIBE"),
            @Result(property = "createTime",column = "CREATE_TIME"),
            @Result(property = "orderStatus",column = "ORDER_STATUS"),
    })
    OrderInfoBO getOrderInfoById(int id);

    /**
     * 通过ID查询feedback
     *
     * @param id
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_feedback where order_id = #{id}")
    @Results({
            @Result(id = true,property = "orderId",column = "order_id"),
            @Result(property = "firstComment",column = "FIRST_COMMENT"),
            @Result(property = "secondComment",column = "SECOND_COMMENT"),
            @Result(property = "thirdComment",column = "THIRD_COMMENT"),
            @Result(property = "status",column = "STATUS"),
    })
    PropertyFeedback getFeedbackById(int id);

    /**
     * 获取3天未完成订单
     * @param
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_info oi left join order_feedback fb on oi.id = fb.order_id where fb.order_id is null and date(CREATE_TIME) <= '${CREATE_TIME}'  and  date(CREATE_TIME) >= '2021-01-01' and (order_status = 'Y-02' or order_status = 'Y-01') order by CREATE_TIME desc")
    @Results({
            @Result(id = true,property = "id",column = "ID"),
            @Result(property = "keyId",column = "KEY_ID"),
            @Result(property = "typeName",column = "TYPE_NAME"),
            @Result(property = "userName",column = "USER_NAME"),
            @Result(property = "storied",column = "STORIED"),
            @Result(property = "address",column = "ADDRESS"),
            @Result(property = "describe",column = "DESCRIBE"),
            @Result(property = "createTime",column = "CREATE_TIME"),
            @Result(property = "orderStatus",column = "ORDER_STATUS"),
    })
    List<OrderInfoBO> getOrderInfoByCreateTime(@Param("CREATE_TIME") String createTime);


    /**
     * 获取5天未完成订单
     * @param
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_info oi left join order_feedback fb on oi.id = fb.order_id where fb.order_id is not null order by CREATE_TIME desc")
    @Results({
            @Result(id = true,property = "id",column = "ID"),
            @Result(property = "keyId",column = "KEY_ID"),
            @Result(property = "typeName",column = "TYPE_NAME"),
            @Result(property = "userName",column = "USER_NAME"),
            @Result(property = "storied",column = "STORIED"),
            @Result(property = "address",column = "ADDRESS"),
            @Result(property = "describe",column = "DESCRIBE"),
            @Result(property = "createTime",column = "CREATE_TIME"),
            @Result(property = "orderStatus",column = "ORDER_STATUS"),
            @Result(property = "firstComment",column = "FIRST_COMMENT"),
            @Result(property = "secondComment",column = "SECOND_COMMENT"),
            @Result(property = "thirdComment",column = "THIRD_COMMENT"),

    })
    List<OrderInfoBO> getFeedback();

    /**
     * 获取5天未完成订单
     * @param
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_info oi left join order_feedback fb on oi.id = fb.order_id where fb.order_id is not null and fb.status = ${status} and date(CREATE_TIME) <= '${CREATE_TIME}' and  date(CREATE_TIME) >= '2021-01-01' and (order_status = 'Y-02' or order_status = 'Y-01') order by CREATE_TIME desc")
    @Results({
            @Result(id = true,property = "id",column = "ID"),
            @Result(property = "keyId",column = "KEY_ID"),
            @Result(property = "typeName",column = "TYPE_NAME"),
            @Result(property = "userName",column = "USER_NAME"),
            @Result(property = "storied",column = "STORIED"),
            @Result(property = "address",column = "ADDRESS"),
            @Result(property = "describe",column = "DESCRIBE"),
            @Result(property = "createTime",column = "CREATE_TIME"),
            @Result(property = "orderStatus",column = "ORDER_STATUS"),
    })
    List<OrderInfoBO> getOrderInfoByDays(@Param("CREATE_TIME") String createTime,@Param("status")int status);
    /**
     * 获取7天未完成订单
     * @param
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_info oi left join order_feedback fb on oi.id = fb.order_id where fb.order_id is not null and fb.status = 2 and date(CREATE_TIME) <= '${CREATE_TIME}' and  date(CREATE_TIME) >= '2021-01-01' and (order_status = 'Y-02' or order_status = 'Y-01') order by CREATE_TIME desc")
    @Results({
            @Result(id = true,property = "id",column = "ID"),
            @Result(property = "keyId",column = "KEY_ID"),
            @Result(property = "typeName",column = "TYPE_NAME"),
            @Result(property = "userName",column = "USER_NAME"),
            @Result(property = "storied",column = "STORIED"),
            @Result(property = "address",column = "ADDRESS"),
            @Result(property = "describe",column = "DESCRIBE"),
            @Result(property = "createTime",column = "CREATE_TIME"),
            @Result(property = "orderStatus",column = "ORDER_STATUS"),
    })
    List<OrderInfoBO> getOrderInfoBy7Days(@Param("CREATE_TIME") String createTime);

//    @DataSource(value = DataSourceType.SLAVE1)
//    @Select("select IM_ACCOUNT from sys_employee where KEY_ID = #{ KEY_ID }")
//    String getImByKeyId(@Param("KEY_ID") String keyId);

    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_info order by date desc")
    List<OrderInfoBO> selectOrderInfoList();

    /**
     * 获取一段时间内的未完成订单
     * @param
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Select("select * from order_info oi left join order_feedback of where oi.id = of.order_id and of.order_id is null and date(CREATE_TIME) <= #{ beginTime } and  date(CREATE_TIME) >= '2021-01-01'  and (order_status = 'Y-02' or order_status = 'Y-01') order by date desc")
    List<OrderInfoBO> selectOrderInfoListByTime(@Param("beginTime") String beginTime);

    /**
     * 新增反馈记录
     * @param feedback
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Insert("insert into order_feedback(order_id,first_comment,status) values(#{orderId},#{firstComment},#{status})")
    int insertFeedback(PropertyFeedback feedback);

    /**
     * 新增反馈记录
     * @param feedback
     * @return
     */
    @DataSource(value = DataSourceType.SLAVE2)
    @Update("update order_feedback set second_comment = #{secondComment}, third_comment = #{thirdComment}, status = #{status} where order_id = #{ orderId }")
    int updateFeedback(PropertyFeedback feedback);
}

